﻿
var ue = UE.getEditor('content', {
    toolbars: [
        ['fullscreen', 'undo', 'redo', 'bold', 'emotion',
            'selectall', 'link', 'insertcode', 'fontfamily','fontsize']],
    enableAutoSave: false,
    maximumWords: 500,
    autoHeightEnabled: false,
    autoFloatEnabled: false,
    fontsize: UeditorFontSizeArray
});
ue.ready(function () {

});

$(function () {
    if ($('#txtvistorEmail').length > 0) {
        $('#txtvistorEmail').mailAutoComplete();
        $(".emailist").css({ marginTop: '0px', marginLeft: '90px' });
    }
    $('#btnok').click(function () {
        if ($('#hCheck').length > 0) {
            if (!layerCheckLogin(true)) {
                return;
            }
        }
        var vistor;
        var visuid;
        var visEmail;
        if ($('#txtvistor').length > 0 && !$.trim($('#txtvistor').val())) {
            layerAlert('敢问阁下尊姓大名？', function () { $('#txtvistor').focus(); });
            return;
        } else {
            vistor = $('#txtvistor').val();
        }
        if ($('#txtvistorEmail').length > 0) {
            if (!$.trim($('#txtvistorEmail').val())) {
                layerAlert('请留下您的Email，有回复将邮件通知您！', function () { $('#txtvistorEmail').focus(); });
                return;
            }
            if (!/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/.test($.trim($('#txtvistorEmail').val()))) {
                layerAlert('阁下输入的Email格式不对哦！', function () { $('#txtvistorEmail').focus(); });
                return;
            }
            visEmail = $('#txtvistorEmail').val();
        }
        if ($("#txtuid").length > 0) {
            visuid = $("#txtuid").val();
        }
        if (!ue.hasContents()) {
            layerAlert('阁下你想对我说啥？', function () { ue.focus(); });
            return;
        }
        //if (ue.getContentTxt().length < 5) {
        //    layerAlert('留言内容不能少于5个字哦！', function () { ue.focus(); });
        //    return;
        //}
        $.post("/system/SendMsg", { VisitorName: $.htmlEncode(vistor), VisitorEmail: visEmail, VisitUid: visuid, content: $.htmlEncode(ue.getContent()) }, function (json) {
            if (json.State == 1) {
                layer.msg('发表成功！', { icon: 1 });
                $(window).scrollTop(0);
                loadMessage();
                changeCount(1);
                clear();
            } else {
                layerAlert(json.Message);
            }
        }, "json");
    });

});

function goSend() {
    var sh = $('#btnok').offset().top;
    $(window).scrollTop(sh);
    ue.focus();
}

function clear() {
    if ($('#txtvistorEmail').length > 0) {
        $('#txtvistor').val('');
        $('#txtvistorEmail').val('');
    }
    ue.setContent('');
}

function loadMessage() {
    $('#dvmsglist').load("/system/message", function () { doUeParse(); });
}

function changeCount(count) {
    $('#spcount').html(parseInt($('#spcount').html()) + count);
}

function replyMsg(i, rid, id, name) {
    if (!layerCheckLogin(true)) {
        return;
    }
    var prefix = '@' + name + ' ';
    var index = layer.prompt({
        formType: 2,
        value: '谢谢支持！',
        title: '回复' + name + '：'
    }, function (value, index, elem) {
        $.post("/system/ReplyMsg", { mid: id, rid: rid, content: $.htmlEncode(prefix + value) }, function (json) {
            if (json.State == 1) {
                layerMsg("回复成功");
                loadMessage();
            } else {
                layerAlert(json.Message);
            }
        });
        layer.close(index);
    });
}

function delMsg(id) {
    layer.confirm('确定删除这条留言吗？', {
        icon: 3,
        title: '提示',
        btn: ['确定', '不要'] //按钮
    }, function () {
        $.post("/system/DeleteMsg", { id: id }, function (json) {
            if (json.State == 1) {
                layer.msg('删除成功！', { icon: 1 });
                loadMessage();
                changeCount(-1);
            } else {
                layerAlert(json.Message);
            }
        }, "json");
    });
}

function delRpMsg(id) {
    layer.confirm('确定删除这条留言吗？', {
        icon: 3,
        title: '提示',
        btn: ['确定', '不要'] //按钮
    }, function () {
        $.post("/system/DeleteRpMsg", { id: id }, function (json) {
            if (json.State == 1) {
                layer.msg('删除成功！', { icon: 1 });
                loadMessage();
            } else {
                layerAlert(json.Message);
            }
        }, "json");
    });
}

function flodReply(o) {
    if ($(o).text() == '折叠') {
        $(o).text('展开');
        $(o).parent().parent().nextAll('div').hide(500);
    } else {
        $(o).text('折叠');
        $(o).parent().parent().nextAll('div').show(500);
    }
}

function agree(id, count, a) {
    doAgree('/system/AgreeMsg', id, count, a);
}

function agreeReply(id, count, a) {
    doAgree('/system/AgreeMsgReply', id, count, a);
}
